/*
 * @Author: webcc
 * @Date: 2022-10-23 00:19:43
 * @LastEditTime: 2022-10-23 10:50:11
 * @email: webcc.coder@qq.com
 */
import React, { Component } from 'react'
import { Route, Redirect } from 'react-router-dom'
import { hasToken } from 'utils/useToken'
export default class AuthRoute extends Component {
    render() {
        const { component: Component, ...rest } = this.props
        return (
            <Route {...rest} render={(props) => {
                if (hasToken()) {
                    return <Component {...props} />
                } else {
                    return <Redirect
                        to={{
                            pathname: '/login',
                            state: {
                                from: props.location.pathname
                            }
                        }}
                    >
                    </Redirect>
                }
            }}></Route>
        )
    }
}
